package com.colorlight.cloud.complete.entity.instructions;

import com.colorlight.cloud.complete.api.CompleteEntityScheduleActions;
import com.colorlight.iot.proto.complete.instruction.CompleteInstruction;
import com.google.protobuf.ByteString;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;

import java.io.Serializable;

/**
 * 回读接收卡连接关系文件，默认回读第一张接收卡的连接关系
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
@Slf4j
public class GetReceiverMappingFile implements CompleteEntityScheduleActions {

    @Data
    @NoArgsConstructor
    @AllArgsConstructor
    @Builder
    public static class InputMsg implements Serializable {
        /**
         * 上传地址
         */
        private String url;
    }

    @Data
    @NoArgsConstructor
    @Builder
    public static class OutputMsg implements Serializable {
    }

    private InputMsg input;
    private OutputMsg output;

    @Override
    public ByteString objectConvertBytes() {
        final CompleteInstruction.GetReceiverMappingFile.InputMsg.Builder inputMsg =
                CompleteInstruction.GetReceiverMappingFile.InputMsg.newBuilder();
        GetReceiverMappingFile.InputMsg thisInput = this.getInput();
        inputMsg.setUrl(thisInput.getUrl());
        final CompleteInstruction.GetReceiverMappingFile.Builder builder =
                CompleteInstruction.GetReceiverMappingFile.newBuilder();
        builder.setInput(inputMsg);
        return builder.build().toByteString();
    }

    @Override
    public GetReceiverMappingFile byteConvertObject(ByteString bytes) {
        this.setOutput(new OutputMsg());
        return this;
    }
}

